﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vite_core.Extensions
{
    public static class CorsServiceExtensions
    {
        private static readonly string PolicyName = "_myAllowSpecificOrigins";


        public static IServiceCollection AddMyCors(this IServiceCollection services)
        {
            services.AddCors(policy =>
            {
                policy.AddPolicy(PolicyName, builder =>
                {
                    builder.WithOrigins("http://localhost:3000")
                           .AllowAnyHeader()
                           .AllowAnyMethod();
                });
            });
            return services;
        }

        public static WebApplication UseMyCors(this WebApplication app)
        {
            app.UseCors(PolicyName);
            return app;
        }
    }
}
